package com.googlecode.sparda.commons.lang;

/**
 * Utility for boolean predicates.
 * @author Fabio Grucci (<i>alias</i> <b>Phoenix</b>)
 * @version 1.0
 * @since 1.0
 */
public final class BooleanUtils {
	
	private BooleanUtils() {/* Utility class */}
	
	/**
	 * Methods that implements a logical multiple xor.
	 * This method return <code>true</code> if and only if only one of 
	 * the boolean value is <code>true</code>.
	 * @param booleans The booleans in xor each other
	 * @return <code>true</code> if and only if one of the boolean value is <code>true</code> 
	 * 			<code>false</code> otherwise
	 */
	public static boolean multipleXor(boolean... booleans) {
		boolean currentXorValue = false; // default is false
		for (boolean b : booleans)
			if(b) {//if find a boolean true
				if(currentXorValue)// if the xor is true
					return false;	//return false (too many true in xor)
				currentXorValue = true; // set the current xor value to true
			}
		return currentXorValue;
	}
}
